import cTitle from "components/title";
import loading from "components/loading";
import { Toast } from "vant";

export default {
  data() {
    return {
      alipay_url: "",
      uid: ""
    };
  },
  methods: {
    //余额充值
    toPay() {
      var that = this;
      $http
        .get(
          "finance.balance.alipay",
          {
            order_sn: this.$route.params.order_pay_id,
            uid: this.$route.params.uid,
            pay_type: 2,
            recharge_money: this.$route.params.recharge_money
          },
          "正在充值"
        )
        .then(
          function(response) {
            if (response.result == 1) {
              that.alipay_url = response.data;
              //alert(response.data);
              that.webToPay();
            } else {
              that.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // error callback
          }
        );
    },
    //订单支付
    toPayOrder() {
      window.location.href = this.$route.params.wxurl;
    },
    //爱心值 支付宝支付
    toLove() {
      var that = this;
      $http.get("plugin.love.Frontend.Modules.Love.Controllers.recharge.alipay", { order_sn: this.$route.params.order_pay_id }, "正在充值").then(
        function(response) {
          if (response.result == 1) {
            that.alipay_url = response.data;
            that.webToPay();
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // error callback
        }
      );
    },
    //冻结币 支付宝支付
    toFrozen() {
      var that = this;
      $http.get("plugin.froze.Frontend.Modules.Froze.Controllers.recharge.alipay", { order_sn: this.$route.params.order_pay_id }, "正在充值").then(
        function(response) {
          if (response.result == 1) {
            that.alipay_url = response.data;
            that.webToPay();
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // error callback
        }
      );
    },
  },
  async activated() {

    if (!this.fun.isWeiXin()) {
      if(this.$route.query.pay_scope == 'auth_payment'){
        let url = decodeURIComponent(this.$route.query.pay_url);
        window.location.href = url;
        return
      }
      if (this.$route.params.status == "2") {
        //订单支付
        this.toPayOrder();
      } else if (this.$route.params.status == "1") {
        if (this.$route.params.tag == "frozen") {
          console.log("冻结币执行了");
          this.toFrozen();
        } else if (this.$route.params.tag == "love") {
          console.log("爱心值执行了");
          this.toLove();
        } else {
          //余额充值
          console.log("余额充值执行了");
          this.toPay();
        }
      }
    }
  },
  components: { cTitle, loading },
  created() {
    let meta_referrer = document.querySelector('#meta_referrer');
    meta_referrer.setAttribute('content', 'unsafe-URL');
  }
};
